function [pred]=bciTestOddball(bci,dat)

% manipulate T to get a two class representation of target/non-target

doWindsorize = isfield(bci,'windsor');
doScale = isfield(bci,'normZscore');

% reshape back to trials X channel X feature
tmpDat = reshape(dat,[size(dat,1),bci.reshape.reSize]);

% windsorize, normalize; see Hoffmann et al., 2008, JNeurosciMeth 167
if doWindsorize||doScale,
    % reshape back to channel X timepoint X trial
    x = permute(tmpDat,[2 3 1]);
    if doWindsorize,
        x = apply(bci.windsor,x);
    end
    if doScale,
        x = apply(bci.normZscore,x);
    end        
    tmpDat=permute(x,[3 1 2]);
end

% some constants
nChan = size(tmpDat,2);
nTargets = length(bci.eventsToClassify);
nLabel = size(dat,1);
nTFlashes = bci.paradigm.nTargetFlashes;

if bci.paradigm.doAverageFlashEvents,
    nFeat =  size(dat,2)/nChan/nTargets/2;
    nMFeat = size(dat,2)/nChan/2;
    % allocate memory
    newDat = zeros(size(dat,1)*2,nChan*nFeat);
    
    % determine classifier output for every possible target
    targetClassOut = zeros(nLabel,nTargets);
    nonTargetClassOut = zeros(nLabel,nTargets);
    targetPred = zeros(nLabel,nTargets);
    nonTargetPred = zeros(nLabel,nTargets);

    for ci=1:nTargets,
        for lab =1:nLabel,
            % get the target features
            targetIdx = (ci-1)*nFeat +(1:nFeat);
            newDat(lab,:)=reshape(tmpDat(lab,:,targetIdx),[1,nChan*nFeat]);
            % get the non-target features
            newDat(lab+nLabel,:) = reshape(tmpDat(lab,:,targetIdx+nMFeat),[1,nChan*nFeat]);
        end
        % get the target classification result
        [targetPred(:,ci) targetClassOut(:,ci)]=bci.oddball.testFunc(bci,newDat(1:nLabel,bci.oddball.featureMask));
        % get the target classification result
        [nonTargetPred(:,ci) nonTargetClassOut(:,ci)]=bci.oddball.testFunc(bci,newDat(1+nLabel:2*nLabel,bci.oddball.featureMask));
    end
else
    nFlashes = nTFlashes*nTargets;
    nFeat =  size(dat,2)/nChan/nTargets/nTFlashes;
    nFeatPerTarget = size(dat,2)/nChan/nTargets;
    % allocate memory
    newDat = zeros(size(dat,1)*nFlashes,nChan*nFeat);

    % determine classifier output for every possible target
    targetClassOut = zeros(nLabel,nTargets,nTFlashes);
    targetPred = zeros(nLabel,nTargets,nTFlashes);
    for ci=1:nTargets,
        for flash = 1:nTFlashes,
            for lab =1:nLabel,
                % get the target features
                targetIdx = (ci-1)*nFeatPerTarget +(flash-1)*nFeat+(1:nFeat);
                newDat(lab,:)=reshape(tmpDat(lab,:,targetIdx),[1,nChan*nFeat]);
            end
            % get the classification result
            [targetPred(:,ci,flash) targetClassOut(:,ci,flash)] = ...
                                bci.oddball.testFunc(bci,newDat(1:nLabel,bci.oddball.featureMask));
        end
    end
    targetClassOut = sum(targetClassOut,3)';
end

if strcmpi(bci.param.classifier,'logreg'),
    % normalize probs to value between 0 and one
    targetClassOut = 2*(targetClassOut-0.5);
    nonTargetClassOut = 2*(nonTargetClassOut-0.5);
end

[dummy,pred] = max(targetClassOut);
% [dummy,pred] = max(targetClassOut-nonTargetClassOut);


